Conditions | 1 |
Paths | 1 |
Total Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | 'use strict'; |
||
13 | function($scope, $interval, $timeout, savegame, state, data, util, reaction) { |
||
14 | $scope.state = state; |
||
15 | $scope.data = data; |
||
16 | $scope.util = util; |
||
17 | |||
18 | let self = this; |
||
19 | |||
20 | self.update = function() { |
||
21 | state.reactions = []; |
||
22 | state.update(state.player); |
||
23 | reaction.processReactions(state.reactions, state.player); |
||
24 | }; |
||
25 | |||
26 | self.updateLoop = function() { |
||
27 | self.update(); |
||
28 | let speed = 1000; |
||
29 | if(state.fasterTicks){ |
||
30 | speed = 1; |
||
31 | state.player.offline--; |
||
32 | if(state.player.offline <= 0){ |
||
33 | state.fasterTicks = 0; |
||
34 | } |
||
35 | } |
||
36 | $timeout(self.updateLoop, speed); |
||
37 | }; |
||
38 | |||
39 | self.startup = function() { |
||
40 | savegame.load(); |
||
41 | let elapsed = Math.floor(Date.now()/1000)-state.player.last_login; |
||
42 | let total = util.calculateValue(data.global_upgrades.offline_time.power.base, |
||
43 | data.global_upgrades.offline_time.power, |
||
44 | state.player.global_upgrades.offline_time); |
||
45 | // lets limit the offline elapsed time |
||
46 | state.player.offline = Math.min(total, state.player.offline+elapsed); |
||
47 | |||
48 | state.loading = false; |
||
49 | // trigger the game loop |
||
50 | $timeout(self.updateLoop, 1000); |
||
51 | $interval(savegame.save, 10000); |
||
52 | }; |
||
53 | |||
54 | $timeout(self.startup); |
||
55 | } |
||
56 | ]); |
||
57 |